package com.customization.assets.formmode.remind;

import com.customization.assets.util.AbstractCronJob;
import com.customization.assets.util.DBTools;
import com.customization.assets.util.DateTools;
import com.customization.commons.LogTool;
import weaver.conn.RecordSet;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Huangwm
 * @description 针对登记时关联了关保资产的实物，检测所关联的关保资产部门与实物帐里的部门不一致时，发起设备提醒流程  不在使用
 */
public class AssetAllotRemind extends AbstractCronJob {
    private LogTool log = new LogTool("/log/assetlog/huangwm/AssetAllotRemind",false);
    private DateTools dateTools = new DateTools();
    private DBTools dbTools = new DBTools();

    @Override
    public void start() throws Exception {
        RecordSet rs1 = new RecordSet();
        rs1.execute("update uf_swzczmxx set synx = DATEDIFF(YEAR,rkrq,getdate()) ");
    }

    /**
     * 获取责任人集合
     * @return
     */
    public List<String> getZrrList(){
        RecordSet rs = new RecordSet();
        List<String> zrrList = new ArrayList<>();
        String sql = "select zrr,syks,dybm  from uf_gbxtzczmxx left join uf_swzczmxx on  uf_gbxtzczmxx.kpwybs=uf_swzczmxx.xzgbxtzc where kpzt=6 and glswzc<>'' and zczt<>6 ";
        log.writeLog("getZrrList-->>>"+sql);
        rs.execute(sql);
        while (rs.next()){
            String zrr = rs.getString("zrr");
            if(!zrrList.contains(zrr)) {
                zrrList.add(zrr);
            }
        }
        return zrrList;
    }

    /**
     * 查询实物关联关保,且关保资产状态为报废状态，实物资产不为报废的数据（不包含报损报废中）
     * @return
     */
    public Map<String,List<Map<String,String>>> getRetirementAsstes(List<String> zrrList){
        Map<String,List<Map<String,String>>> datas = new HashMap<String,List<Map<String,String>>>();
        if(zrrList.size()==0) return datas;
        //String sql = " select uf_swzczmxx.id as swid,uf_gbxtzczmxx.id as gbid,xzgbxtzc,kpwybh,uf_gbxtzczmxx.kph,kpzt,zczt,swzcbh,zclx,ppss,ggxhss,zrr,syks,dybm from uf_swzczmxx left join uf_gbxtzczmxx on  uf_swzczmxx.xzgbxtzc=uf_gbxtzczmxx.kpwybs  where xzgbxtzc<>'' and kpzt=6 and zczt<>6 ";
        String sql = "select uf_swzczmxx.id as swid,uf_gbxtzczmxx.id as gbid,xzgbxtzc,kpwybh,uf_gbxtzczmxx.kph,kpzt,zczt,swzcbh,zclx,ppss,ggxhss,zrr,syks,dybm  from uf_gbxtzczmxx left join uf_swzczmxx on  uf_gbxtzczmxx.kpwybs=uf_swzczmxx.xzgbxtzc where kpzt=6 and glswzc<>'' and zczt<>6 ";
        log.writeLog("getRetirementAsstes-->>>"+sql);
        RecordSet rs2 = new RecordSet();
        rs2.execute(sql);
        while (rs2.next()){
            String zrr = rs2.getString("zrr");
            List<Map<String,String>> mapList = new ArrayList<>();
            for (int i=0;i<zrrList.size();i++){
                if(zrr.equals(zrrList.get(i))){
                    Map<String,String> data = new HashMap<>();
                    data.put("swid",rs2.getString("swid"));
                    data.put("gbid",rs2.getString("gbid"));
                    data.put("kpwybh",rs2.getString("xzgbxtzc"));
                    data.put("kph",rs2.getString("kph"));
                    data.put("swzcbh",rs2.getString("swzcbh"));
                    data.put("zrr",rs2.getString("zrr"));
                    data.put("syks",rs2.getString("syks"));
                    data.put("dybm",rs2.getString("dybm"));
                    data.put("pp",rs2.getString("ppss"));
                    data.put("ggxh",rs2.getString("ggxhss"));
                    mapList.add(data);
                }
            }
            //按责任人汇总对应名下的资产
            datas.put(zrr,mapList);
        }
        return datas;
    }

}
